var t = require("../../../api.js"), e = getApp(), o = !1, a = !1, s = 2;

Page({
    data: {
        hide: 1,
        qrcode: "",
        scrollLeft: 0,
        scrollTop: 0,
      hideDialog:true,
      radioValue:1,
      pickerIndex: 0,
      post_code:'',
      express_no:'',
      words:'',
      sendorder_id:-1,
    },
    onLoad: function(t) {
        this.systemInfo = wx.getSystemInfoSync();
        var n = wx.getStorageSync("store");
        this.setData({
            store: n
        }), e.pageOnLoad(this);
        var i = this;
        o = !1, a = !1, s = 2, i.loadOrderList(t.status || -1);
        var r = 0;
        r = t.status >= 2 ? 600 : 0, i.setData({
            scrollLeft: r
        });
    },
    onReady: function() {},
    onShow: function() {
        e.pageOnShow(this);
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    loadOrderList: function(o) {
        console.log("load list");
        void 0 == o && (o = -1);
        var a = this;
        a.setData({
            status: o
        }), wx.showLoading({
            title: "正在加载",
            mask: !0
        }), e.request({
            url: t.mch.ptorder.refund_list,
            data: {
                status: a.data.status
            },
            success: function(t) {
                0 == t.code && a.setData({
                    order_list: t.data.list
                }), a.setData({
                    show_no_data_tip: 0 == t.data.list.length
                }), 4 != o ;
              if (t.code == 0 && a.data.status == 1){
                  a.setData({
                    expressList: t.data.express_list.public
                  });
                }
            },
            complete: function() {
                wx.hideLoading();
            }
        });
    },
    countDown: function() {

        var t = this;
        setInterval(function() {
            var e = t.data.order_list;
            for (var o in e) {
                var a = new Date(e[o].limit_time_ms[0], e[o].limit_time_ms[1] - 1, e[o].limit_time_ms[2], e[o].limit_time_ms[3], e[o].limit_time_ms[4], e[o].limit_time_ms[5]) - new Date(), s = parseInt(a / 1e3 / 60 / 60 / 24, 10), n = parseInt(a / 1e3 / 60 / 60 % 24, 10), i = parseInt(a / 1e3 / 60 % 60, 10), r = parseInt(a / 1e3 % 60, 10);
                s = t.checkTime(s), n = t.checkTime(n), i = t.checkTime(i), r = t.checkTime(r), 
                e[o].limit_time = {
                    days: s,
                    hours: n > 0 ? n : "00",
                    mins: i > 0 ? i : "00",
                    secs: r > 0 ? r : "00"
                }, t.setData({
                    order_list: e
                });
            }
        }, 1e3);
    },
    checkTime: function(t) {
        return (t = t > 0 ? t : 0) < 10 && (t = "0" + t), t;
    },
    onReachBottom: function() {
      console.log(" onReachBottom ");
        var n = this;
        a || o || (a = !0, e.request({
            url: t.mch.ptorder.refund_list,
            data: {
                status: n.data.status,
                page: s
            },
            success: function(t) {
                if (0 == t.code) {
                    var e = n.data.order_list.concat(t.data.list);
                    n.setData({
                        order_list: e
                    }), 0 == t.data.list.length && (o = !0);
                }
                s++;
            },
            complete: function() {
                a = !1;
            }
        }));
    },
    goHome: function(t) {
        wx.redirectTo({
            url: "/pages/pt/index/index"
        });
    },
    diaCancel: function(){
      this.setData({
        hideDialog: true
      });
    },
    diaConfirm: function () {
      wx.showLoading({
        title: "正在加载",
        mask: !0
      });
      var a = this;
      console.log(a.data);
      e.request({
        url: t.mch.ptorder.send,
        data: {
          is_express: a.data.radioValue,
          express: a.data.expressList[a.data.pickerIndex],
          post_code:a.data.post_code,
          express_no:a.data.express_no,
          words:a.data.words,
          order_id: a.data.sendorder_id
        },
        success: function (t) {
          if (t.code == 0 && a.data.status == 1) {
            wx.showModal({
              title: "提示",
              content: t.msg,
              showCancel: !1,
              confirmText: "确认",
              success: function (t) {
                a.loadOrderList(a.data.status);
              }
            });
            a.setData({
              hideDialog: true
            });
          }
        },
        complete: function () {
          wx.hideLoading();
        }
      });
    },
    hide: function(t) {
        this.setData({
            hide: 1
        });
    },
    confirmTui: function(o) {
        var a = this;
        wx.showModal({
            title: "提示",
            content: "确认同意退货退款？确认通过后退款金额将直接返还给用户",
            cancelText: "否",
            confirmText: "是",
            success: function(s) {
                if (s.cancel) return !0;
                s.confirm && (wx.showLoading({
                    title: "操作中"
                }), e.request({
                    url: t.mch.ptorder.refund_do,
                    data: {
                      order_refund_id: o.currentTarget.dataset.id,
                      type: 1,
                      action: 1,
                    },
                    success: function(t) {
                        wx.hideLoading(), wx.showModal({
                            title: "提示",
                            content: t.msg,
                            showCancel: !1,
                            success: function(t) {
                                t.confirm && a.loadOrderList(a.data.status);
                            }
                        });
                    }
                }));
            }
        });
    },
    rejectTui: function (o) {
      var a = this;
      wx.showModal({
        title: "提示",
        content: "确认拒绝该退货退款申请？",
        cancelText: "否",
        confirmText: "是",
        success: function (s) {
          if (s.cancel) return !0;
          s.confirm && (wx.showLoading({
            title: "操作中"
          }), e.request({
            url: t.mch.ptorder.refund_do,
            data: {
              order_refund_id: o.currentTarget.dataset.id,
              type: 1,
              action: 2,
            },
            success: function (t) {
              wx.hideLoading(), wx.showModal({
                title: "提示",
                content: t.msg,
                showCancel: !1,
                success: function (t) {
                  t.confirm && a.loadOrderList(a.data.status);
                }
              });
            }
          }));
        }
      });
    },
    confirmHuan: function (o) {
      var a = this;
      wx.showModal({
        title: "提示",
        content: "确认同意换货？",
        cancelText: "否",
        confirmText: "是",
        success: function (s) {
          if (s.cancel) return !0;
          s.confirm && (wx.showLoading({
            title: "操作中"
          }), e.request({
            url: t.mch.ptorder.refund_do,
            data: {
              order_refund_id: o.currentTarget.dataset.id,
              type: 2,
              action: 1,
            },
            success: function (t) {
              wx.hideLoading(), wx.showModal({
                title: "提示",
                content: t.msg,
                showCancel: !1,
                success: function (t) {
                  t.confirm && a.loadOrderList(a.data.status);
                }
              });
            }
          }));
        }
      });
    },
    rejectHuan: function (o) {
      var a = this;
      wx.showModal({
        title: "提示",
        content: "确认拒绝该换货申请？",
        cancelText: "否",
        confirmText: "是",
        success: function (s) {
          wx.showLoading({
            title: "操作中"
          });
          e.request({
            url: t.mch.ptorder.refund_do,
            data: {
              order_refund_id: o.currentTarget.dataset.id,
              type: 2,
              action: 2,
            },
            success: function (t) {
              wx.hideLoading();
              wx.showModal({
                title: "提示",
                content: t.msg,
                showCancel: !1,
                success: function (t) {
                  t.confirm && a.loadOrderList(a.data.status);
                }
              });
            }
          });
        }
      });
    },
    switchNav: function(t) {
        var e = t.currentTarget.dataset.status;
        wx.redirectTo({
            url: "/mch/m/ptrefund/order?status=" + e
        });
    },
    goToRefundDetail: function(t) {
        var e = t.currentTarget.dataset.refund_id;
        wx.navigateTo({
            url: "/pages/pt/order-refund-detail/order-refund-detail?id=" + e
        });
    },
    confirmCancel: function(b){
      wx.showLoading({
        title: "正在加载",
        mask: !0
      });
      var a = this;
      e.request({
        url: t.mch.ptorder.apply_delete_status,
        data: {
          status: 1,
          id: b.currentTarget.dataset.id
        },
        success: function (t) {
          if (t.code == 0 ) {
            wx.showModal({
              title: "提示",
              content: t.msg,
              showCancel: !1,
              confirmText: "确认",
              success: function (t) {
                a.loadOrderList(a.data.status);
              }
            });
          } else {
            wx.showModal({
              title: "提示",
              content: t.msg,
            });
          }
        },
        error: function (t) {
          wx.hideLoading();
        },
        complete: function () {
          wx.hideLoading();
        }
      });
    },
    rejectCancel: function (b) {
      wx.showLoading({
        title: "正在加载",
        mask: !0
      });
      var a = this;
      e.request({
        url: t.mch.ptorder.apply_delete_status,
        data: {
          status: 0,
          id: b.currentTarget.dataset.id
        },
        success: function (t) {
          if (t.code == 0 ) {
            wx.showModal({
              title: "提示",
              content: t.msg,
              showCancel: !1,
              confirmText: "确认",
              success: function (t) {
                a.loadOrderList(a.data.status);
              }
            });
          }else{
            wx.showModal({
              title: "提示",
              content: t.msg,
            });
          }
        },
        error:function(t){
          wx.hideLoading();
        },
        complete: function () {
          wx.hideLoading();
        }
      });
    },
});